# 导入访问MySQL的模块
import mysql.connector
class starSpiderPipeline(object):
    # 定义构造器，初始化要写入的文件
    def __init__(self):
        self.conn = mysql.connector.connect(user='root', password='yaoguang',
            host='39.105.161.214', port='3308',
            database='aiyue', use_unicode=True)
        self.cur = self.conn.cursor()
    # 重写close_spider回调方法，用于关闭数据库资源
    def close_spider(self, spider):
        print('----------关闭数据库资源-----------')
        # 关闭游标
        self.cur.close()
        # 关闭连接
        self.conn.close()
    def process_item(self, item, spider):
        print(1)
        self.cur.execute("INSERT INTO aiyue VALUES(null, %s, %s, %s)", (item['name'], item['img'], item['info_link']))
        self.conn.commit()